package Dame;

public class BinarySearchDame1 {
    public static void main(String[] args) {
        int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        int a = 10;
        int num = BinarySearch(a,arr);
        System.out.println(num);
    }

    private static int BinarySearch(int a, int[] arr) {
        int max = arr.length-1;
        int min = 0;
        while (min<=max){
            int mid = (max + min)>>1;
           if (arr[mid]>a){
               max = mid+1;
           }else if (arr[mid]<a){
               min = mid+1;
           }else {
               return mid;
           }
        }
        return -1;
    }
}
